<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"><head>
      <#include "/common/elibs.html">
    <!-- 让IE8/9支持媒体查询，从而兼容栅格 -->
  </head>
  <script>var index;
  </script><body>
    <div class="x-body">
        <form class="layui-form">
            <div class="layui-form-item">
              <label for="userName" class="layui-form-label">
                  <span class="x-red">*</span>姓名
              </label>
              <div class="layui-input-inline">
                  <input type="text" id="nickName" name="nickName" lay-verify="required" placeholder="请输入"
                  autocomplete="off" class="layui-input" >
              </div>
              <div class="layui-form-mid layui-word-aux">
                  <span class="x-red">*</span>
              </div>
          </div><div class="layui-form-item">
                <label for="userName" class="layui-form-label">
                    <span class="x-red">*</span>登录名称
                </label>
                <div class="layui-input-inline">
                    <input type="text" id="userName" name="userName" lay-verify="required" placeholder="请输入"
                           autocomplete="off" class="layui-input" >
                </div>
                <div class="layui-form-mid layui-word-aux">
                    <span class="x-red">*</span>
                </div>
            </div><div class="layui-form-item">
                <label for="userPhone" class="layui-form-label">
                    <span class="x-red">*</span>用户年龄
                </label>
                <div class="layui-input-inline">
                    <input type="text" id="userAge" name="userAge" lay-verify="number" placeholder="请输入"
                           autocomplete="off" class="layui-input" >
                </div>
                <div class="layui-form-mid layui-word-aux">
                    <span class="x-red">*</span>
                </div>
            </div><div class="layui-form-item">
                <label for="userPhone" class="layui-form-label">
                    <span class="x-red">*</span>用户电话
                </label>
                <div class="layui-input-inline">
                    <input type="text" id="userPhone" name="userPhone" lay-verify="phone" placeholder="请输入"
                           autocomplete="off" class="layui-input" >
                </div>
                <div class="layui-form-mid layui-word-aux">
                    <span class="x-red">*</span>
                </div>
            </div>
            <div class="layui-form-item" id="parentsId" >
                <label for="status" class="layui-form-label">
                    <span class="x-red">*</span>用户状态
                </label>
                <div class="layui-input-inline">
                    <select lay-filter="tcaParentsId" id="status" name="status"
                            value="" lay-verify="required">
                        <option >请选择</option>
                        <option value="0">停用</option>
                        <option value="1">启用</option>
                        <option value="2">出现违规情况而被停用</option>
                    </select>
                </div>
                <div class="layui-form-mid layui-word-aux">
                    <span class="x-red">*</span>
                </div>
            </div>
            <div class="layui-form-item"  >
                <label for="userRoleId" class="layui-form-label">
                    <span class="x-red">*</span>用户角色
                </label>
                <div class="layui-input-inline">
                    <select lay-filter="tcaParentsId" id="userRoleId" name="userRoleId" value="" lay-verify="required">
                        <option >请选择</option>
                    </select>
                </div>
                <div class="layui-form-mid layui-word-aux">
                    <span class="x-red">*</span>
                </div>
            </div>
          <div class="layui-form-item">
              <label for="userName" class="layui-form-label">
              </label>
              <button  class="layui-btn" lay-filter="add" lay-submit="">
                  提交
              </button>
          </div>
      </form>
    </div>
    <script>

        layui.use(['form','layer'], function(){
            $ = layui.jquery;
            var form = layui.form
                ,layer = layui.layer, layedit = layui.layedit;


            ajaxFun('get','/pc/role/getRoleInfoList',null,function(data){
                if(data.code != 0){
                    alertFun(data);
                }else{
                    var html = "<option >请选择</option>";
                    $("#userRoleId").html("");
                    for(var i=0;i<data.data.length;i++){
                        html += "<option value='"+data.data[i].idUserRole+"'>"+data.data[i].roleName+"</option>";
                    }
                    $("#userRoleId").append(html);
                    form.render();
                }
            })
            //自定义验证规则
            form.verify({
                nickName: function(value){
                    if(value.length < 0){
                        return '用户名不能为空';
                    }
                },
                userName: function(value){
                    if(value.length < 0){
                        return '姓名不能为空';
                    }
                },
                userAge: function(value){
                    if(value.length < 0){
                        return '年龄不能为空';
                    }
                },
                userPhone: function(value){
                    if(value.length < 0){
                        return '手机号不能为空';
                    }
                },
                status: function(value){
                    if(value.length < 0){
                        return '用户状态不能为空';
                    }
                },
                userRoleId: function(value){
                    if(value.length < 0){
                        return '用户类型不能为空';
                    }
                },
//            ,pass: [/(.+){6,12}$/, '密码必须6到12位']
                /*,repass: function(value){
                    if($('#L_pass').val()!=$('#L_repass').val()){
                        return '两次密码不一致';
                    }
                }*/
            });

            //监听级别
            form.on('select(status)', function(data){
                var value = data.value;
                $("#status").val(value);
            });

            //监听级别
            form.on('select(userRoleId)', function(data){
                var value = data.value;
                $("#userRoleId").val(value);
            });
            //监听提交
            form.on('submit(add)', function(t){
                var params = {
                    //tcaDescribe : layui.layedit.getContent(index),
                    // "tcaParentsId" : $("#tcaParentsId").val(),
                    "nickName" : $("#nickName").val(),
                    "userName" : $("#userName").val(),
                    "userAge" : $("#userAge").val(),
                    "userPhone" : $("#userPhone").val(),
                    "status" : $("#status").val(),
                    "userRoleId" : $("#userRoleId").val()
                }
                if(true){
                    ajaxFun('post','/pc/user/addUserInfo',params,function(data){
                        if(data.code != 0){
                            alertFun(data);
                        }else{
                            window.location.href= path + "/modules/users/list.html";
                            console.log("success !");
                        }
                    })
                }

                //发异步，把数据提交给php
                /*layer.alert("增加成功", {icon: 6},function () {
                    // 获得frame索引
                    var index = parent.layer.getFrameIndex(window.name);
                    //关闭当前frame
                    parent.layer.close(index);
                });*/
                return false;
            });


        });
    </script></body></html>